//
//  AboutViewController.swift
//  NDAi
//
//  Created by 丸子 on 2024/6/20.
//

import UIKit
import YYText

class AboutViewController: BaseViewController {
    
    lazy var iconIV: UIImageView = {
        let imageView = UIImageView()
        imageView.image = UIImage(named: "ai_launch_logo")
        imageView.contentMode = .scaleToFill
        imageView.clipsToBounds = true
        return imageView
    }()
    
    lazy var titleLb: UILabel = {
        let label = UILabel()
        label.textColor = Theme.color.text_d2
        label.font = UIFont.pingFangSCRegular(ofSize: 16)
        label.textAlignment = .center
        label.text = "V" + Device.VERSION_NAME
        return label
    }()
    
    private lazy var updateBtn: UIButton = {
        let button = UIButton(type: .custom)
        button.titleForNormal = "检查更新"
        button.titleFont = UIFont.pingFangSCRegular(ofSize: 16)
        button.backgroundColor = UIColor(hexString: "#25262B")
        button.allRound(22)
        return button
    }()
    
    lazy var beianLb: UILabel = {
        let label = UILabel()
        label.textColor = Theme.color.text_d3
        label.font = UIFont.pingFangSCMedium(ofSize: 15)
        label.textAlignment = .center
        label.text = "粤ICP备:2023097485号-2A"
        return label
    }()
    
    lazy var mailLb: UILabel = {
        let label = UILabel()
        label.textColor = Theme.color.text_d3
        label.font = UIFont.pingFangSCMedium(ofSize: 15)
        label.textAlignment = .center
        label.text = "客服邮箱Email:service@letonglive.com"
        return label
    }()
    
    lazy var xyLabel: YYLabel = {
        let label = YYLabel()
        label.numberOfLines = 0
        label.textAlignment = .center
        // 创建富文本字符串
        let fullText = "《用户协议》 丨 《隐私政策》"
        let attributedString = NSMutableAttributedString(string: fullText)
        // 设置通用字体属性
        let fullRange = NSRange(location: 0, length: attributedString.length)
        attributedString.addAttributes([
            .font: UIFont.pingFangSCMedium(ofSize: 15), // 替换成你需要的字体
            .foregroundColor: Theme.color.text_d3 // 替换成你需要的颜色
        ], range: fullRange)
        // 设置《用户协议》的链接和颜色
        let userAgreementRange = (fullText as NSString).range(of: "《用户协议》")
        attributedString.yy_setTextHighlight(userAgreementRange, color: UIColor(hexString: "#45FFFF"), backgroundColor: nil) { _, _, _, _ in
            if let url = URL(string: "\(apiHost)/api/text/contract") {
                UIApplication.shared.open(url)
            }
        }
        // 设置《隐私政策》的链接和颜色
        let privacyPolicyRange = (fullText as NSString).range(of: "《隐私政策》")
        attributedString.yy_setTextHighlight(privacyPolicyRange, color: UIColor(hexString: "#45FFFF"), backgroundColor: nil) { _, _, _, _ in
            if let url = URL(string: "\(apiHost)/api/text/privacy") {
                UIApplication.shared.open(url)
            }
        }
        label.attributedText = attributedString
        return label
    }()
    
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        self.editNav(isCurrent: true)
    }
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        self.editNav(isCurrent: false)
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = UIColor(hexString: "#F3F2F7")
        self.navigationItem.title = "关于我们"
        
        self.view.addSubviews([iconIV, titleLb, updateBtn, beianLb, mailLb, xyLabel])
        
        iconIV.snp.makeConstraints { make in
            make.top.equalToSuperview().offset(64)
            make.centerX.equalToSuperview()
        }
        
        titleLb.snp.makeConstraints { make in
            make.top.equalTo(iconIV.snp.bottom).offset(20)
            make.centerX.equalToSuperview()
        }
        
        updateBtn.snp.makeConstraints { make in
            make.top.equalTo(titleLb.snp.bottom).offset(40)
            make.leading.trailing.equalToSuperview().inset(50)
            make.height.equalTo(44)
        }
        
        beianLb.snp.makeConstraints { make in
            make.bottom.equalTo(self.safeBottom).offset(-20)
            make.centerX.equalToSuperview()
        }
        
        mailLb.snp.makeConstraints { make in
            make.bottom.equalTo(beianLb.snp.top).offset(-10)
            make.centerX.equalToSuperview()
        }
        
        xyLabel.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.bottom.equalTo(mailLb.snp.top).offset(-10)
        }
        
        updateBtn.setClosureTouchUpInside_k {
            
        }
    }
    
    
    
    
    
}
